import 'package:demo/component/component_button.dart';
import 'package:demo/component/component_common.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:demo/views/mine/mine_city_controller.dart';
import 'package:flutter_pickers/pickers.dart';

// 设置地区
class MineCityView extends GetView<MineCityController> {
  // 路由地址
  static const String routeName = '/mine_city';
  const MineCityView({super.key});

  @override
  Widget build(BuildContext context) {
    Get.lazyPut(() => MineCityController());
    return Scaffold(
      appBar: AppBar(
        title: const Text('修改地区'),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(12.0),
        child: Column(
          children: [
            _checkLocation(context),
            _buildSubmit(),
          ],
        ),
      ),
    );
  }

  _checkLocation(BuildContext context) {
    return GetBuilder<MineCityController>(builder: (builder) {
      return InkWell(
        onTap: () {
          Pickers.showAddressPicker(
            context,
            pickerStyle: ComponentCommon.pickerStyle(),
            initProvince: controller.province,
            initCity: controller.city,
            addAllItem: false,
            onChanged: (p, c, t) {
              controller.onChanged(p, c);
            },
            onConfirm: (p, c, t) {
              controller.onChanged(p, c);
            },
          );
        },
        child: _buildCity(),
      );
    });
  }

  _buildCity() {
    return TextField(
      enabled: false,
      controller: controller.cityController,
    );
  }

  _buildSubmit() {
    return ComponentButton(
      label: '提  交',
      onTap: () {
        // 提交
        controller.submit();
      },
    );
  }
}
